package com.gr3g.dev.engine.exception;

import org.apache.log4j.Logger;

/** @author Gregory Tardivel */
public final class GameException extends Exception {

    /** Numéro de série. */
    private static final long serialVersionUID = -2498447015022417953L;
    /** LOGGER. */
    private static final Logger LOG = Logger.getLogger(GameException.class);

    /** Constructeur.
     * @param pMessage */
    public GameException(final String pMessage) {
        super(pMessage);
    }

    /** Constructeur.
     * @param pMessage
     * @param pCause */
    public GameException(final String pMessage, final Throwable pCause) {
        super(pMessage, pCause);
    }

    /** Erreur.
     * @param pMessage
     * @param pCause
     * @param pBlocked
     * @throws GameException */
    public static void error(
            final String pMessage,
            final Throwable pCause,
            final boolean pBlocked)
                    throws GameException {
        LOG.error(pMessage, pCause);
        if (pBlocked) {
            throw new GameException(pMessage, pCause);
        }
    }

    /** Erreur.
     * @param pMessage
     * @param pBlocked
     * @throws GameException */
    public static void error(final String pMessage, final boolean pBlocked)
            throws GameException {
        LOG.error(pMessage);
        if (pBlocked) {
            throw new GameException(pMessage);
        }
    }

    /** Erreur.
     * @param pCause
     * @param pBlocked
     * @throws GameException */
    public static void error(final Throwable pCause, final boolean pBlocked)
            throws GameException {
        LOG.error("Erreur rencontrée", pCause);
        if (pBlocked) {
            throw new GameException("Erreur rencontrée", pCause);
        }
    }

}
